﻿using System.Collections.Generic;
using Microsoft.Xna.Framework;

namespace HMEngine.HMInputs {
    public class HMInputManager : GameComponent {
        private static readonly Dictionary<string, HMInputDevice> myDevices = new Dictionary<string, HMInputDevice>();
        
        public HMInputManager(Game game) : base(game) {}

        public static void AddDevice(string name, HMInputDevice newDevice) {
            myDevices.Add(name, newDevice);
        }

        public static void RemoveDevice(string name) {
            myDevices.Remove(name);
        }

        public static HMInputDevice GetDevice(string name) {
            if (myDevices.ContainsKey(name)) return myDevices[name];

            return null;
        }

        public override void Update(GameTime gameTime) {
            if (Game.IsActive) {
                foreach (HMInputDevice device in myDevices.Values) {
                    device.Update();
                }
            }

            base.Update(gameTime);
        }

        public override void Initialize() {
            foreach (HMInputDevice device in myDevices.Values) {
                device.Initialize();
            }

            base.Initialize();
        }
    }
}